package myQueue;

public class MySequentialQueue<T> {        //非循环队列泛型类

    final int MaxSize = 100;            //假设容量为100
    private T[] data;                //存放队列中的元素
    private int front, rear;            //队头队尾指针

    public MySequentialQueue()            //构造方法
    {
        data = (T[]) new Object[MaxSize];
        front = -1;
        rear = -1;
    }

    //队列的基本运算算法
    public boolean empty()    //判断队列是否为空
    {
        return front == rear;
    }

    public void push(T e)            //元素e进队
    {
        if (rear == MaxSize - 1)        //队满
            throw new IllegalArgumentException("队列已满");
        rear++;
        data[rear] = e;
    }

    public T pop()                //出队元素
    {
        if (empty())            //队空
            throw new IllegalArgumentException("队空");
        front++;
        return (T) data[front];
    }

    public T peek()            //取队头元素
    {
        if (empty())            //队空
            throw new IllegalArgumentException("队空");
        return (T) data[front + 1];
    }


}
